package com.yz.jdd.module.main.adapter;

import android.content.Context;
import android.graphics.Color;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.yz.jdd.R;
import com.yz.jdd.module.main.entity.FilterBean;

import java.util.List;


public class FilterTypeAdapter extends BaseAdapter {

    private Context context;
    private List<FilterBean.PayTypeBean> beanList;

    public FilterTypeAdapter(Context context, List<FilterBean.PayTypeBean> beanList) {
        this.context = context;
        this.beanList = beanList;
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public Object getItem(int i) {
        return beanList.get(i);
    }

    @Override
    public int getCount() {
        return beanList.size();
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
        ViewHolder viewHolder;
        if (view == null) {
            view = LayoutInflater.from(context).inflate(R.layout.item_filter, viewGroup, false);
            viewHolder = new ViewHolder();
            viewHolder.nameTextView = (TextView) view.findViewById(R.id.name_tv);
            view.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) view.getTag();
        }
        viewHolder.nameTextView.setText(beanList.get(i).getName());
        if (beanList.get(i).isSelect()) {
            viewHolder.nameTextView.setBackgroundResource(R.mipmap.select_bg);
            viewHolder.nameTextView.setTextColor(context.getResources().getColor(R.color.colorPrimary));
        } else {
            viewHolder.nameTextView.setBackgroundResource(R.drawable.listview_bg);
            viewHolder.nameTextView.setTextColor(Color.parseColor("#121F33"));
        }
        return view;
    }

    class ViewHolder {
        TextView nameTextView;
    }
}
